package com.yhq.spring.spring.conf;

import com.yhq.spring.spring.service.UserService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
/**
 * 自定义Bean的属性值
 * @author hqyin
 * @date 2023/4/6 2:42 下午
 */
//@Component
@Slf4j
public class TestInitializingMethod implements InitializingBean, DisposableBean {
    private String name;
    private Integer age;
    private UserService userService;

    public TestInitializingMethod(UserService userService) {
        log.info("=====================>执行构造方法");
        userService = userService;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("=====================>实现了InitializingBean接口初始化属性");
        name="Lisa";
    }

    @PostConstruct
    public void init() {
        log.info("=====================>实现了@PostConstruct注解初始化属性");
        age = 12;
    }

    @PreDestroy
    public void preDestroy(){
        log.info("=====================>实现了@PreDestroy注解销毁之前");
    }

    @Override
    public void destroy() throws Exception {
        log.info("=====================>实现了DisposableBean接口销毁之前");
    }

    public void show() {
        log.info("=====================>name:{},age:{}",name,age);
    }
}
